import Log from "../utils/log";
import ro from "element-ui/src/locale/lang/ro";

if (window.JavaContext) {
    JavaContext.inWebBrowser = false;
}
if (window.JavaContext == undefined) {
    window.JavaContext = (function() {
        function JavaContext() {}

        JavaContext.inWebBrowser = true;

        JavaContext.getAppName = function() {
            return "DEBUG ME_VIEWER";
        };
        JavaContext.consoleLook = function(){};

        JavaContext.exitApp = function() {
            console.log("EXIT APPLICATION...");
        };

        JavaContext.getGPSServiceStatus = function() {};

        JavaContext.setGPSServiceEnable = function() {
            console.log("setGPSServiceEnable...");
        };
        JavaContext.getMarkImages = function(){return "[]";}
        JavaContext.getChangedGpsData = function() {
            return '[{"time":1,"lon":113,"lat":34},{"time":2,"lon":114,"lat":35}]';
        };
        JavaContext.getCurrentGPS = function() {
            var o = {
                time: 1,
                lon: Math.random() + 113,
                lat: Math.random() + 34
            };
            return JSON.stringify(o);
        };

        JavaContext.outputGPSFile = function() {
            return "oooo";
        };
        JavaContext.ReadTxtFile = function() {
            //return '[{"time":1,"lon":113,"lat":34},{"time":2,"lon":114,"lat":35}]';
            return '{"type":"FeatureCollection","name":"graphic","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}},"features":[{"type":"Feature","properties":{"gvtype":1},"geometry":{"type":"LineString","coordinates":[[-106.57205552687822,24.969605526318766,-8145.380801172114],[-80.09668458633712,20.309985100050838,-12481.999059294152],[-51.02240268207718,34.31595230320116,-7910.404558661312]]}}]}\n';
        };

        JavaContext.importGPSFile = function() {
            return JsContext.slotSelectGpsFile("storage/emulated/0/mev/GPS/2020.json");
        };

        /**
         * 调用文件管理器，参数参见 FileTypes 类
         * 调用:
         *     JavaContext.loadFileBrowser(FileTypes.GEO_JSON.isFile, FileTypes.GEO_JSON.rootPath, FileTypes.GEO_JSON.pathAll, "JsContext.onGeoJsonFileLoaded");
         * @param isFile 是否请求文件
         * @param rootPath 请求的根目录
         * @param pathAll 是否可以访问系统根目录 (/storage/emulated/0/)
         * @param jsContextFunctionName 回调方法，默认只有一个参数 filepath
         */
        JavaContext.loadFileBrowser = function(isFile, rootPath, pathAll, jsContextFunctionName) {
            Log.info(`load fileBrowserActivity...${isFile}, ${rootPath}, ${pathAll}, ${jsContextFunctionName}`);
            eval(jsContextFunctionName + "()");
        };

        JavaContext.read = function(filepath) {
            Log.info(`read file: ${filepath}`);
        };

        JavaContext.write = function(filepath, content) {
            Log.info(`write file to ${filepath} with content ${content}`);
        };

        JavaContext.isNetOk = function() {
            return true;
        };
        return JavaContext;
    })();
}
